<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   Python快速搭建自动回复微信公众号  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/23813.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466460686: Accept with keywords: (title(0.25):Python,公众,社区,数盟, topn(0.333333333333):社区,机器人,数盟,合作伙伴,行业资讯,数据挖掘,官网,数据分析,Python,职业规划,模式,基础架构,开发包,文章,服务器,源代码,聊天,python,图灵,公众,可视化,编程语言,利用,代码,平台,人工智能,消息,可选项,文本,行业).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    Python快速搭建自动回复微信公众号
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    Python快速搭建自动回复微信公众号 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,66] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech/devl">
       编程语言
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/23813.html">
          Python快速搭建自动回复微信公众号
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          637 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech/devl" rel="category tag">
          编程语言
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <div class="article_content" id="article_content">
        <div class="markdown_views">
         <p>
          来源：CSDN 作者：
          <a class="user_name" href="http://my.csdn.net/tobacco5648" target="_blank">
           liuwons
          </a>
         </p>
         <p id="python快速搭建自动回复微信公众号">
          在之前的一篇文章
          <a href="http://blog.csdn.net/tobacco5648/article/details/50600310">
           Python利用
           <strong>
            AIML
           </strong>
           和
           <strong>
            Tornado
           </strong>
           搭建聊天机器人
          </a>
          <a class="replace_word" href="http://lib.csdn.net/base/5" target="_blank" title="微信开发知识库">
           微信
          </a>
          订阅号 中用
          <strong>
           aiml
          </strong>
          实现了一个简单的英文聊天机器人订阅号。但是只能处理英文消息，现在用
          <a href="http://www.tuling123.com/">
           <strong>
            图灵机器人
           </strong>
          </a>
          来实现一个中文的聊天机器人订阅号。
         </p>
         <p>
          这里主要介绍如何利用
          <strong>
           Python
          </strong>
          的
          <a href="http://www.tornadoweb.org/en/stable/">
           <strong>
            Tornado
           </strong>
          </a>
          Web框架以及
          <a href="https://github.com/wechat-python-sdk/wechat-python-sdk">
           wechat-python-sdk
          </a>
          微信公众平台
          <strong>
           Python
          </strong>
          开发包来快速搭建微信公众号。
         </p>
         <p>
          完整的公众号代码
          <strong>
           GitHub
          </strong>
          地址：
          <a href="https://github.com/liuwons/green">
           green
          </a>
          ，由于目前此公众号有一些功能正在开发中，此完整代码会与下文所描述的代码有不一致的地方，但是自动回复的功能会一直保留。
         </p>
         <p>
          本文搭建的微信公众号为
          <code>
           Ms_haoqi
          </code>
          ，可以扫码关注后测试效果
         </p>
         <p>
          <img src="http://img.blog.csdn.net/20160419140351193"/>
         </p>
         <p>
          自动回复效果:
          <br/>
          <img src="http://img.blog.csdn.net/20160419140549694"/>
         </p>
         <h2 id="安装python库">
          <p name="t1">
          </p>
          安装Python库
         </h2>
         <p>
          通过
          <strong>
           pip
          </strong>
          安装
          <strong>
           wechat-python-sdk
          </strong>
          ，
          <strong>
           Requests
          </strong>
          以及
          <strong>
           Tornado
          </strong>
         </p>
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686a09024c5157206559" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <span class="crayon-language">
             Python
            </span>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            pip install tornado
pip install wechat-sdk
pip install requests
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-57686a09024c5157206559-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024c5157206559-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024c5157206559-3">
                 3
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-57686a09024c5157206559-1">
                 <span class="crayon-e">
                  pip
                 </span>
                 <span class="crayon-e">
                  install
                 </span>
                 <span class="crayon-e">
                  tornado
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024c5157206559-2">
                 <span class="crayon-e">
                  pip
                 </span>
                 <span class="crayon-e">
                  install
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-o">
                  -
                 </span>
                 <span class="crayon-e">
                  sdk
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024c5157206559-3">
                 <span class="crayon-e">
                  pip
                 </span>
                 <span class="crayon-e">
                  install
                 </span>
                 <span class="crayon-v">
                  requests
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0011 seconds] -->
         <p>
         </p>
         <h2 id="订阅号申请">
          <p name="t2">
          </p>
          订阅号申请
         </h2>
         <p>
          要搭建订阅号，首先需要在微信公众平台官网进行注册，注册网址:
          <a href="https://mp.weixin.qq.com/">
           微信公众平台
          </a>
          。
         </p>
         <p>
          目前个人用户可以免费申请微信订阅号，虽然很多权限申请不到，但是基本的消息回复是没有问题的。
         </p>
         <h2 id="服务器接入">
          <p name="t3">
          </p>
          服务器接入
         </h2>
         <p>
          具体的接入步骤可以参考官网上的
          <a href="http://mp.weixin.qq.com/wiki/8/f9a0b8382e0b77d87b3bcc1ce6fbc104.html">
           接入指南
          </a>
          。
         </p>
         <p>
          本订阅号的配置为：
          <br/>
          <img src="http://img.blog.csdn.net/20160419140703746"/>
         </p>
         <p>
          配置里的URL为服务器提供订阅号后台的url路径，本文用到的源代码配置的是
          <strong>
           <a href="http://server_ip/wx">
            http://server_ip/wx
           </a>
          </strong>
          其中
          <strong>
           server_ip
          </strong>
          是运行源代码的主机的公网ip地址。
         </p>
         <p>
          <strong>
           Token
          </strong>
          可以设置为任意字符串。
         </p>
         <p>
          <strong>
           EncodingAESKey
          </strong>
          可以选择随机生成。
         </p>
         <p>
          消息加密方式可以设置为比较简单的明文模式。
         </p>
         <p>
          接受并处理微信服务器发送的接入请求的关键代码为Tornado的一个Handle,
          <code>
           wx.py
          </code>
          :
         </p>
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686a09024d7210865549" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <span class="crayon-language">
             Python
            </span>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            import tornado.escape
import tornado.web

from wechat_sdk import WechatConf
conf = WechatConf(
    token='your_token', # 你的公众号Token
    appid='your_appid', # 你的公众号的AppID
    appsecret='your_appsecret', # 你的公众号的AppSecret
    encrypt_mode='safe',  # 可选项：normal/compatible/safe，分别对应于 明文/兼容/安全 模式
    encoding_aes_key='your_encoding_aes_key'  # 如果传入此值则必须保证同时传入 token, appid
)

from wechat_sdk import WechatBasic
wechat = WechatBasic(conf=conf)

class WX(tornado.web.RequestHandler):
    def get(self):
        signature = self.get_argument('signature', 'default')
        timestamp = self.get_argument('timestamp', 'default')
        nonce = self.get_argument('nonce', 'default')
        echostr = self.get_argument('echostr', 'default')
        if signature != 'default' and timestamp != 'default' and nonce != 'default' and echostr != 'default' \
                and wechat.check_signature(signature, timestamp, nonce):
            self.write(echostr)
        else:
            self.write('Not Open')
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-9">
                 9
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-10">
                 10
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-11">
                 11
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-12">
                 12
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-13">
                 13
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-14">
                 14
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-15">
                 15
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-16">
                 16
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-17">
                 17
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-18">
                 18
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-19">
                 19
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-20">
                 20
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-21">
                 21
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-22">
                 22
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-23">
                 23
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-24">
                 24
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024d7210865549-25">
                 25
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024d7210865549-26">
                 26
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-57686a09024d7210865549-1">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  escape
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-2">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  web
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-3">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-4">
                 <span class="crayon-st">
                  from
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  wechat_sdk
                 </span>
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  WechatConf
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-5">
                 <span class="crayon-v">
                  conf
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  WechatConf
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-6">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  token
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-s">
                  'your_token'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-c">
                  # 你的公众号Token
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-7">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  appid
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-s">
                  'your_appid'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-c">
                  # 你的公众号的AppID
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-8">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  appsecret
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-s">
                  'your_appsecret'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-c">
                  # 你的公众号的AppSecret
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-9">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  encrypt_mode
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-s">
                  'safe'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-c">
                  # 可选项：normal/compatible/safe，分别对应于 明文/兼容/安全 模式
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-10">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  encoding_aes_key
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-s">
                  'your_encoding_aes_key'
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-c">
                  # 如果传入此值则必须保证同时传入 token, appid
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-11">
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-12">
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-13">
                 <span class="crayon-st">
                  from
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  wechat_sdk
                 </span>
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  WechatBasic
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-14">
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  WechatBasic
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  conf
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-v">
                  conf
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-15">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-16">
                 <span class="crayon-t">
                  class
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  WX
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  web
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  RequestHandler
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-17">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  def
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  get
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-18">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  signature
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get_argument
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'signature'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-19">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  timestamp
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get_argument
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'timestamp'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-20">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  nonce
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get_argument
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'nonce'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-21">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  echostr
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get_argument
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'echostr'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-22">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  signature
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  !=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  and
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  timestamp
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  !=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  and
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  nonce
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  !=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  and
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  echostr
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  !=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  \
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-23">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  and
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  check_signature
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  signature
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  timestamp
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  nonce
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-24">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  write
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  echostr
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024d7210865549-25">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  else
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024d7210865549-26">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  write
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'Not Open'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0346 seconds] -->
         <p>
          此代码的作用就是验证消息是来自微信官方服务器后直接返回echostr。
         </p>
         <p>
          启动后台的
          <code>
           main.py
          </code>
          代码：
         </p>
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686a09024df606241038" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <span class="crayon-language">
             Python
            </span>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            import tornado.web
import tornado.httpserver
from tornado.options import define, options

settings = {
            'static_path': os.path.join(os.path.dirname(__file__), 'static'),
            'template_path': os.path.join(os.path.dirname(__file__), 'view'),
            'cookie_secret': 'e440769943b4e8442f09de341f3fea28462d2341f483a0ed9a3d5d3859f==78d',
            'login_url': '/',
            'session_secret': "3cdcb1f07693b6e75ab50b466a40b9977db123440c28307f428b25e2231f1bcc",
            'session_timeout': 3600,

            'port': 5601,
            'wx_token': 'weixin',
            }

web_handlers = [
        (r'/wx', wx.WX),
        ]

define("port", default=settings['port'], help="run on the given port", type=int)

if __name__ == '__main__':
    app = tornado.web.Application(web_handlers, **settings)
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-9">
                 9
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-10">
                 10
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-11">
                 11
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-12">
                 12
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-13">
                 13
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-14">
                 14
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-15">
                 15
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-16">
                 16
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-17">
                 17
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-18">
                 18
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-19">
                 19
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-20">
                 20
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-21">
                 21
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-22">
                 22
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-23">
                 23
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-24">
                 24
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-25">
                 25
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-26">
                 26
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024df606241038-27">
                 27
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024df606241038-28">
                 28
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-57686a09024df606241038-1">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  web
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-2">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  httpserver
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-3">
                 <span class="crayon-st">
                  from
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  options
                 </span>
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  define
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  options
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-4">
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-5">
                 <span class="crayon-v">
                  settings
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  {
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-6">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'static_path'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  os.path
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  join
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-k ">
                  os.path
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  dirname
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  __file__
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'static'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-7">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'template_path'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  os.path
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  join
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-k ">
                  os.path
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  dirname
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  __file__
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'view'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-8">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'cookie_secret'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'e440769943b4e8442f09de341f3fea28462d2341f483a0ed9a3d5d3859f==78d'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-9">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'login_url'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  '/'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-10">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'session_secret'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  "3cdcb1f07693b6e75ab50b466a40b9977db123440c28307f428b25e2231f1bcc"
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-11">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'session_timeout'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-cn">
                  3600
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-12">
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-13">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'port'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-cn">
                  5601
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-14">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'wx_token'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'weixin'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-15">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  }
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-16">
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-17">
                 <span class="crayon-v">
                  web_handlers
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  [
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-18">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-i">
                  r
                 </span>
                 <span class="crayon-s">
                  '/wx'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  wx
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  WX
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-19">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  ]
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-20">
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-21">
                 <span class="crayon-e">
                  define
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  "port"
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  default
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-v">
                  settings
                 </span>
                 <span class="crayon-sy">
                  [
                 </span>
                 <span class="crayon-s">
                  'port'
                 </span>
                 <span class="crayon-sy">
                  ]
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  help
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-s">
                  "run on the given port"
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  type
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-k ">
                  int
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-22">
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-23">
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  __name__
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  ==
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  '__main__'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-24">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  app
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  web
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  Application
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  web_handlers
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  *
                 </span>
                 <span class="crayon-o">
                  *
                 </span>
                 <span class="crayon-v">
                  settings
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-25">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  options
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  parse_command_line
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-26">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  http_server
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  httpserver
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  HTTPServer
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  app
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024df606241038-27">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  http_server
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  listen
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  options
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  port
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024df606241038-28">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  ioloop
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  IOLoop
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  instance
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  start
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0228 seconds] -->
         <p>
          配置好程序源代码后运行，确认运行无误后再在公众号设置页面点击
          <strong>
           提交
          </strong>
          ，如果程序运行没问题，会显示接入成功。
         </p>
         <h2 id="接入图灵机器人">
          <p name="t4">
          </p>
          接入图灵机器人
         </h2>
         <p>
          要接入图灵机器人，首先需要在官网申请API Key。
         </p>
         <p>
          申请到之后可以利用以下代码包装一个自动回复接口：
         </p>
         <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686a09024e7005480451" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <span class="crayon-language">
             Python
            </span>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            # -*- coding: utf-8 -*-
import json
import requests
import traceback

class TulingAutoReply:
    def __init__(self, tuling_key, tuling_url):
        self.key = tuling_key
        self.url = tuling_url

    def reply(self, unicode_str):
        body = {'key': self.key, 'info': unicode_str.encode('utf-8')}
        r = requests.post(self.url, data=body)
        r.encoding = 'utf-8'
        resp = r.text
        if resp is None or len(resp) == 0:
            return None
        try:
            js = json.loads(resp)
            if js['code'] == 100000:
                return js['text'].replace('&lt;br&gt;', '\n')
            elif js['code'] == 200000:
                return js['url']
            else:
                return None
        except Exception:
            traceback.print_exc()
            return None
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-9">
                 9
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-10">
                 10
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-11">
                 11
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-12">
                 12
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-13">
                 13
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-14">
                 14
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-15">
                 15
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-16">
                 16
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-17">
                 17
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-18">
                 18
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-19">
                 19
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-20">
                 20
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-21">
                 21
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-22">
                 22
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-23">
                 23
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-24">
                 24
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-25">
                 25
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-26">
                 26
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024e7005480451-27">
                 27
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024e7005480451-28">
                 28
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-57686a09024e7005480451-1">
                 <span class="crayon-c">
                  # -*- coding: utf-8 -*-
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-2">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  json
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-3">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  requests
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-4">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  traceback
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-5">
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-6">
                 <span class="crayon-t">
                  class
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  TulingAutoReply
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-7">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  def
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  __init__
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tuling_key
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tuling_url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-8">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  key
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  tuling_key
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-9">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  tuling_url
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-10">
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-11">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-r">
                  def
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  reply
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  unicode_str
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-12">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  body
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  {
                 </span>
                 <span class="crayon-s">
                  'key'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  key
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'info'
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  unicode_str
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  encode
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'utf-8'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-sy">
                  }
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-13">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  r
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  requests
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  post
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  data
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-v">
                  body
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-14">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  r
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  encoding
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'utf-8'
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-15">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  r
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  text
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-16">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  resp
                 </span>
                 <span class="crayon-st">
                  is
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-t">
                  None
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  or
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  len
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  ==
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-cn">
                  0
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-17">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-t">
                  None
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-18">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  try
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-19">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  js
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  json
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  loads
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  resp
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-20">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  js
                 </span>
                 <span class="crayon-sy">
                  [
                 </span>
                 <span class="crayon-s">
                  'code'
                 </span>
                 <span class="crayon-sy">
                  ]
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  ==
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-cn">
                  100000
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-21">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  js
                 </span>
                 <span class="crayon-sy">
                  [
                 </span>
                 <span class="crayon-s">
                  'text'
                 </span>
                 <span class="crayon-sy">
                  ]
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  replace
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  '&lt;br&gt;'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  '\n'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-22">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  elif
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  js
                 </span>
                 <span class="crayon-sy">
                  [
                 </span>
                 <span class="crayon-s">
                  'code'
                 </span>
                 <span class="crayon-sy">
                  ]
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  ==
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-cn">
                  200000
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-23">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  js
                 </span>
                 <span class="crayon-sy">
                  [
                 </span>
                 <span class="crayon-s">
                  'url'
                 </span>
                 <span class="crayon-sy">
                  ]
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-24">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  else
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-25">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-t">
                  None
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-26">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  except
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  Exception
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024e7005480451-27">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  traceback
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  print_exc
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024e7005480451-28">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-t">
                  None
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0294 seconds] -->
         <p>
         </p>
         <h2 id="编写公众号自动回复代码">
          <p name="t5">
          </p>
          编写公众号自动回复代码
         </h2>
         <p>
          利用
          <a href="https://github.com/wechat-python-sdk/wechat-python-sdk">
           wechat-python-sdk
          </a>
          微信公众平台
          <strong>
           Python
          </strong>
          开发包可以很容易地处理公众号的所有消息。
         </p>
         <p>
          如下为处理来自微信官方服务器的微信公众号消息的
          <strong>
           Tornado
          </strong>
          Handler对象(此代码会获取公众号收到的用户消息并调用刚刚包装的图灵机器人API自动回复)
          <code>
           wx.py
          </code>
          部分代码：
          <br/>
          <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
         </p>
         <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686a09024f0410269504" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
          <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <span class="crayon-title">
           </span>
           <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
            <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-wrap-button" title="切换自动换行">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-expand-button" title="点击展开代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-copy-button" title="复制代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
             <div class="crayon-button-icon">
             </div>
            </div>
            <span class="crayon-language">
             Python
            </span>
           </div>
          </div>
          <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
          </div>
          <div class="crayon-plain-wrap">
           <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
            # -*- coding: utf-8 -*-
import tornado.escape
import tornado.web

auto_reply = TulingAutoReply(key, url) # key和url填入自己申请到的图灵key以及图灵请求url

class WX(tornado.web.RequestHandler):
    def wx_proc_msg(self, body):
        try:
            wechat.parse_data(body)
        except ParseError:
            print 'Invalid Body Text'
            return
        if isinstance(wechat.message, TextMessage): # 消息为文本消息
            content = wechat.message.content
            reply = auto_reply.reply(content)
            if reply is not None:
                return wechat.response_text(content=reply)
            else:
                return wechat.response_text(content=u"不知道你说的什么")
        return wechat.response_text(content=u'知道了')

    def post(self):
        signature = self.get_argument('signature', 'default')
        timestamp = self.get_argument('timestamp', 'default')
        nonce = self.get_argument('nonce', 'default')
        if signature != 'default' and timestamp != 'default' and nonce != 'default' \
                and wechat.check_signature(signature, timestamp, nonce):
            body = self.request.body.decode('utf-8')
            try:
                result = self.wx_proc_msg(body)
                if result is not None:
                    self.write(result)
            except IOError, e:
                return
           </textarea>
          </div>
          <div class="crayon-main" style="">
           <table class="crayon-table">
            <tbody>
             <tr class="crayon-row">
              <td class="crayon-nums " data-settings="show">
               <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-1">
                 1
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-2">
                 2
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-3">
                 3
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-4">
                 4
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-5">
                 5
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-6">
                 6
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-7">
                 7
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-8">
                 8
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-9">
                 9
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-10">
                 10
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-11">
                 11
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-12">
                 12
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-13">
                 13
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-14">
                 14
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-15">
                 15
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-16">
                 16
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-17">
                 17
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-18">
                 18
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-19">
                 19
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-20">
                 20
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-21">
                 21
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-22">
                 22
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-23">
                 23
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-24">
                 24
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-25">
                 25
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-26">
                 26
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-27">
                 27
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-28">
                 28
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-29">
                 29
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-30">
                 30
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-31">
                 31
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-32">
                 32
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-33">
                 33
                </div>
                <div class="crayon-num crayon-striped-num" data-line="crayon-57686a09024f0410269504-34">
                 34
                </div>
                <div class="crayon-num" data-line="crayon-57686a09024f0410269504-35">
                 35
                </div>
               </div>
              </td>
              <td class="crayon-code">
               <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
                <div class="crayon-line" id="crayon-57686a09024f0410269504-1">
                 <span class="crayon-c">
                  # -*- coding: utf-8 -*-
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-2">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  escape
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-3">
                 <span class="crayon-r">
                  import
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  web
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-4">
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-5">
                 <span class="crayon-v">
                  auto_reply
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  TulingAutoReply
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  key
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  url
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-c">
                  # key和url填入自己申请到的图灵key以及图灵请求url
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-6">
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-7">
                 <span class="crayon-t">
                  class
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  WX
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  tornado
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  web
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  RequestHandler
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-8">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  def
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  wx_proc_msg
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  body
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-9">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  try
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-10">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  parse_data
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  body
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-11">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  except
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  ParseError
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-12">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  print
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'Invalid Body Text'
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-13">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-14">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  isinstance
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  message
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  TextMessage
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-c">
                  # 消息为文本消息
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-15">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  message
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  content
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-16">
                 <span class="crayon-e">
                 </span>
                 <span class="crayon-v">
                  reply
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  auto_reply
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  reply
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-17">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  reply
                 </span>
                 <span class="crayon-st">
                  is
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  not
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-t">
                  None
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-18">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  response_text
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-v">
                  reply
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-19">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  else
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-20">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  response_text
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-i">
                  u
                 </span>
                 <span class="crayon-s">
                  "不知道你说的什么"
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-21">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  response_text
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  content
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-i">
                  u
                 </span>
                 <span class="crayon-s">
                  '知道了'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-22">
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-23">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  def
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  post
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-24">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  signature
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get_argument
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'signature'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-25">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  timestamp
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get_argument
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'timestamp'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-26">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  nonce
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  get_argument
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'nonce'
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-27">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  signature
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  !=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  and
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  timestamp
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  !=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  and
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  nonce
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  !=
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-s">
                  'default'
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-sy">
                  \
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-28">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  and
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  wechat
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  check_signature
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  signature
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  timestamp
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  nonce
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-29">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  body
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  request
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-v">
                  body
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  decode
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-s">
                  'utf-8'
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-30">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  try
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-31">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  result
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-o">
                  =
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  wx_proc_msg
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  body
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-32">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  if
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-e">
                  result
                 </span>
                 <span class="crayon-st">
                  is
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  not
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-t">
                  None
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-33">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-r">
                  self
                 </span>
                 <span class="crayon-sy">
                  .
                 </span>
                 <span class="crayon-e">
                  write
                 </span>
                 <span class="crayon-sy">
                  (
                 </span>
                 <span class="crayon-v">
                  result
                 </span>
                 <span class="crayon-sy">
                  )
                 </span>
                </div>
                <div class="crayon-line crayon-striped-line" id="crayon-57686a09024f0410269504-34">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  except
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-k ">
                  IOError
                 </span>
                 <span class="crayon-sy">
                  ,
                 </span>
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-v">
                  e
                 </span>
                 <span class="crayon-o">
                  :
                 </span>
                </div>
                <div class="crayon-line" id="crayon-57686a09024f0410269504-35">
                 <span class="crayon-h">
                 </span>
                 <span class="crayon-st">
                  return
                 </span>
                </div>
               </div>
              </td>
             </tr>
            </tbody>
           </table>
          </div>
         </div>
         <!-- [Format Time: 0.0281 seconds] -->
        </div>
       </div>
       <div class="bdsharebuttonbox tracking-ad bdshare-button-style0-16" data-bd-bind="1461720543785" data-mod="popu_172">
       </div>
       <div id="digg">
        <dl class="digg digg_enable" id="btnDigg">
         <dt>
         </dt>
        </dl>
       </div>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/24678.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/20140917125452915416-216x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24678.html" rel="bookmark" title="python3中的正则模块">
         python3中的正则模块
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24675.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/t015b337bd75d9ef893-161x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24675.html" rel="bookmark" title="注释是恶魔，请不要再写一行注释">
         注释是恶魔，请不要再写一行注释
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24660.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/u16130037972892789947fm21gp0-300x157.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24660.html" rel="bookmark" title="如何从Github上轻松安装R包">
         如何从Github上轻松安装R包
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24654.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/df53fac99fc53ba5a90666abcca25e6d_b-267x200.png"/>
        </a>
        <a class="link" href="http://dataunion.org/24654.html" rel="bookmark" title="简单形象又有趣地说说强大的神经网络">
         简单形象又有趣地说说强大的神经网络
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F23813.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/23813.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/23813.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>